package com.veer.shop.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.veer.shop.annotation.ApiControllerLog;
import com.veer.shop.annotation.ApiSecured;
import com.veer.shop.annotation.CurrentUser;
import com.veer.shop.config.ApiUrlConfig;
import com.veer.shop.param.AdminMenuParam;
import com.veer.shop.pojo.AdminMenu;
import com.veer.shop.pojo.CurrentUserInfo;
import com.veer.shop.pojo.ResponseData;
import com.veer.shop.service.impl.admin.AdminMenuServiceImpl;

/**
 * 后台菜单 控制器
 * 
 * @author WangBin
 * 2020年8月11日-下午5:52:04
 */
@RestController
public class MenuController {
	
	@Autowired
	private AdminMenuServiceImpl adminMenuServiceImpl;
	
	/**
	 * 获取后台菜单列表
	 */
	@ApiSecured
	@ApiControllerLog(description = "获取后台菜单列表")
	@RequestMapping( path = ApiUrlConfig.API_ADMIN_MENU_LIST_URL, method = RequestMethod.POST)
	public ResponseData<?> getList(@RequestBody(required = false) AdminMenuParam menuParam)
	{
		return adminMenuServiceImpl.getList(menuParam);
	}
	
	/**
	 * 新增|更新后台菜单
	 */
	@ApiSecured
	@ApiControllerLog(description = "新增|更新后台菜单")
	@RequestMapping( path = ApiUrlConfig.API_ADMIN_MENU_UPDATE_URL, method = RequestMethod.POST)
	public ResponseData<?> update(@CurrentUser CurrentUserInfo userInfo, @RequestBody AdminMenu adminMenuEntity)
	{
		adminMenuEntity.setOpName(userInfo.getName());
		return adminMenuServiceImpl.update(adminMenuEntity);
	}
	
	/**
	 * 删除后台菜单
	 */
	@ApiSecured
	@ApiControllerLog(description = "删除后台菜单")
	@RequestMapping( path = ApiUrlConfig.API_ADMIN_MENU_DELETE_URL, method = RequestMethod.POST)
	public ResponseData<?> delete(@RequestParam(name = "menu_id", defaultValue = "") String menuId)
	{
		return adminMenuServiceImpl.delete(menuId);
	}
	
	/**
	 * 获取后台菜单
	 */
	@ApiSecured
	@ApiControllerLog(description = "获取后台菜单")
	@RequestMapping( path = ApiUrlConfig.API_ADMIN_MENU_GET_URL, method = RequestMethod.GET)
	public ResponseData<?> get(@RequestParam(name = "menu_id", defaultValue = "") Integer menuId)
	{
		return adminMenuServiceImpl.get(menuId);
	}
}
